package com.bba.manager.as.controller;

import com.bba.manager.as.service.IOldPartsService;
import com.bba.manager.common.model.as.OldParts;
import com.bba.manager.common.model.as.VO.oldPartsQuery;
import com.bba.manager.common.util.ResponseEnum;
import com.bba.manager.common.util.ResponseVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 汽车旧件表 前端控制器
 * </p>
 *
 * @author SYANDZZY
 * @since 2025-08-12
 */
@RestController
@RequestMapping("/oldParts")
public class OldPartsController {
    @Autowired
    private IOldPartsService oldPartsService;
//创建旧件单
    @PostMapping("/sava")
    public ResponseVO sava(@RequestBody OldParts oldParts){
        oldPartsService.save(oldParts);
        return ResponseVO.success(oldParts);
    }
    //查询旧件单
    @GetMapping("/getOldParts")
    public ResponseVO list(oldPartsQuery oldPartsQuery){
        return ResponseVO.success(oldPartsService.listByPage(oldPartsQuery));
    }
    //删除旧件单
    @DeleteMapping("/delete")
    public ResponseVO delete(@RequestParam Long id){
        oldPartsService.removeById(id);
        return ResponseVO.success(ResponseEnum.STOCK_DELETED_SUCCESS.getMessage());
    }
    //修改订单状态
    @PutMapping("/update")
    public ResponseVO update(@RequestParam Long id,
                             @RequestParam String status){
        oldPartsService.updateOldPartsStatus(id,status);
        return ResponseVO.success(ResponseEnum.SUCCESS.getMessage());
    }
}
